package cn.niit.letuseatdemo.util;

import cn.niit.letuseatdemo.entity.domain.Store;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Description:
 * @Author: zhang_bowen
 * @CreateTime： 2022/12/3 18:11
 */
public class LoginStoreUtil {
    /**
     * @Description: 获取当前用户的 HttpSession 对象
     * @Author: yang_yong
     * @CreateTime: 2022/10/12 21:39
     * @return: javax.servlet.http.HttpSession
     **/
    public static HttpSession getHttpSession() {
        HttpServletRequest request = ((ServletRequestAttributes)
                RequestContextHolder.getRequestAttributes())
                .getRequest();
        return request.getSession();
    }
    /**
     * @Description: 获取当前登录用户（Store）对象
     * @Author: yang_yong
     * @CreateTime: 2022/10/11 0:53
     * @return: cn.niit.hospital.entity.domain.SysUser
     **/
    public static Store getLoginStore(){
        Object obj = getHttpSession().getAttribute("store");
        if(null != obj){
            return (Store) obj;
        }
        return null;
    }
}